<?php


namespace Blog\App\Event;

use Hx\App;
use Hx\Error;
use Hx\Response;
use Hx\View;

/**
 * 组件Event类
 * Class Widget
 * @package Blog\App\Event
 */
class Widget {

    /**
     * 渲染侧边栏
     * @return string
     */
    public static function side() {
        $viewData['category'] = App::Model('Category->getAll');
        $viewData['popular'] = App::Model('Blog->getPopular');
        $viewData['newComment'] = App::Model('Comment->getNew');
        return View::display('side.html', 2, $viewData);
    }

    /**
     * 处理错误触发事件
     * @param Error $error
     */
    public static function error(Error $error) {
        $code = $error->getStatusCode();
        Response::sendRedirect('/error/' . $code . '.html');
    }
}